
# 
#     Timer.py : provide a basic timer for simulation
#     
    
class Timer():
  def __init__(self,start_time = 0.0, end_time=4.0,fps = 25,callback=None):
    self.start_time = start_time
    self.end_time = end_time
    self.fps = fps
    self.time = self.start_time
    self.callbacks = []
    if callback is not None:
      self.callbacks.append(callback)
     
  def run(self):
    print "entering run" ,  self.time,  self.end_time 
    while self.time < self.end_time:
      print "running",self.time
      self.do_callbacks()
      self.time += 1.0 / self.fps

      
  def add_callback(self,object,method):
    self.callbacks.append((object,method))

  def do_callbacks(self):
    for (obj,meth) in self.callbacks:
      meth(self.time)    
    
    
  